﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>查看模块配置步骤</title>
    <link href="../lib/layui/css/layui.min.css" rel="stylesheet" />
    <link href="../x-admin/css/font.css" rel="stylesheet" />
    <link href="../x-admin/css/xadmin.css" rel="stylesheet" />
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/layui/layui.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
    <style>
        .unoperate {
            display: none;
        }
        .layui-bg-red .layui-layer-content {
            padding:1px;
        }
    </style>
</head>
<body>
    <div class="layui-card-header" style="">
        <button class="layui-btn operateBtn unoperate" onclick="addItem(this)">
            <i class="layui-icon"></i>添加步骤
        </button>
        <!--<div class="layui-inline" id="nodeTipDiv">
        <i class="layui-icon layui-icon-fire" style="color:red"></i>
        <span class="layui-inline" style="color:red" id="tipspan"></span>
    </div>-->
        <div class="layui-inline layui-form unoperate" id="rootAttrDiv" lay-filter="rootAttrForm">
            <input type="checkbox"  name="mlflag" id="mlflagcb" title="机器学习">
            <input type="checkbox"  name="type" id="typecb" title="切分模式提取">
        </div>


    </div>
    <div class="layui-card-body" style="">
        <input type="hidden" id="stepNo" class="layui-input" />
        <table class="layui-table layui-form" id="moudlestepinfo" lay-filter="moudlestepinfo">
        </table>
    </div>
    <script type="text/html" id="barmoudle">
        <a title="查看" href="javascript:;" lay-event="catitem"><i class="layui-icon">&#xe63c;</i>查看</a>
        <a class="operateBtn" title="编辑" href="javascript:;" lay-event="edititem"><i class="layui-icon">&#xe642;</i>编辑</a>
        <a class="operateBtn" title="删除" href="javascript:;" lay-event="deleteitem"><i class="layui-icon">&#xe640;</i>删除</a>
    </script>
    <script type="text/javascript">
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }
        var moudlefileName = getrequest().fileName;
        var moudleCode = getrequest().moudleCode;
        layui.use(['table','form'], function () {
            var table = layui.table;
            var form = layui.form;
            table.render({
                elem: '#moudlestepinfo'
                , method: 'get'
                , headers: {
                    user: getCookie("userinfo"),
                    version: getCookie("version")
                }
                , skin: 'row'
                , even: true
                , page: false
                , url: localStorage.getItem('hosttingaddr') + '/api/moudlecfgfile/detail'  //数据接口
                , cols: [[ //表头
                    { field: 'number', title: '步骤序号' }
                    , { field: 'filePath', title: '配置文件' }
                    , { field: 'executeType', title: '执行类型' }
                    , { field: 'executeCode', title: '执行代码' }
                    , { field: 'code', title: '步骤编码' }
                    , { field: 'moduleName', title: '中文名称' }
                    , { fixed: 'right', title: "操作", width: 300, align: 'center', toolbar: '#barmoudle' }
                ]]
                , done: function (res) {
                    layui.$("#stepNo").val(res.stepNo);
                    if (res.nodeTip != null && res.nodeTip != "") {
                        layer.msg(res.nodeTip, {
                            time: 0,
                            offset: ['40px','15px'],
                            skin: "layui-bg-red",
                        });
                    }
                    if (res.isOperate != 1) {
                        layui.$(".operateBtn").addClass("unoperate");
                    }
                    else {
                        layui.$(".operateBtn").removeClass("unoperate");
                    }
                    if (res.isSection == true) {
                        form.val('rootAttrForm', {
                            "mlflag": res.mlflag,
                            "type": res.type
                        });
                        layui.$("#mlflagcb").attr("disabled", true);
                        layui.$("#typecb").attr("disabled", true);
                        layui.$("#rootAttrDiv").removeClass("unoperate");
                    } else {
                        layui.$("#rootAttrDiv").addClass("unoperate");
                    }
                }
                , where: getWhere()

            });

            //监听行工具事件
            table.on('tool(moudlestepinfo)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                var steptype = data.executeType;
                fileN = data.filePath;
                switch (layEvent) {
                    case 'catitem':
                        if (steptype == 'xml') {
                            layer.open({
                                type: 2,
                                title: '公共配置文件内容',
                                maxmin: true,
                                shadeClose: true, //点击遮罩关闭层
                                area: ['1350px', '600px'],
                                content: 'moudleitemdetail.html' + '?fileName=' + fileN// iframe链接地址
                            });
                        } else {
                            layer.msg("不是xml文件，不能查看");
                        }
                        break;
                    case 'edititem':
                        //editCfgFile(this,'@item.number','@ViewBag.FilePath')
                        var iteminfo = btoa(window.encodeURIComponent(JSON.stringify(data)));
                        layer.open({
                            type: 2,
                            title: '编辑流程配置文件单项内容',
                            maxmin: true,
                            shadeClose: true,
                            area: ['600px', '480px'],
                            content: 'moudleitemedit.html?moudleitem=' + iteminfo + '&fileName=' + moudlefileName// iframe链接地址
                        });
                        break;
                    case 'deleteitem':
                        var number = data.number;
                        var filePath = data.filePath;
                        var fileP = btoa(filePath);
                        var moduleFile = btoa(moudlefileName);
                        layer.confirm('确认要删除吗？', function (index) {
                            layui.$.ajax({
                                type: "post",
                                url: localStorage.getItem('hosttingaddr') + '/api/moudlecfgfile/deleteitem',
                                headers: {
                                    user: getCookie("userinfo"),
                                    version: getCookie("version")
                                },
                                data: "{'number':'" + number + "','filePath':'" + fileP + "','moduleFile':'" + moduleFile + "'}",
                                success: function (data) {
                                    layer.msg('已删除!', { icon: 1, time: 1000 });
                                    table.reload("moudlestepinfo");
                                    layer.close(index);
                                }
                            });
                        });
                        break;
                }
            });
            function getWhere() {
                var where = {};
                where.fileName = moudlefileName;
                where.moudleCode = moudleCode;
                return where;
            }

        });
        // 添加配置项
        function addItem(obj) {

            var fileName = btoa(window.encodeURIComponent(JSON.stringify(getrequest().fileName)));
            var stepNo = btoa(window.encodeURIComponent(JSON.stringify(layui.$("#stepNo").val())));
            layer.open({
                type: 2,
                title: '添加配置项',
                maxmin: true,
                shadeClose: true,
                area: ['600px', '480px'],
                content: 'moudleitemadd.html' + '?fileName=' + fileName + '&stepNo=' + stepNo
            });
        }
    </script>
</body>
</html>